using AutoMapper;
using ManagementApi.Models;
using ManagementApi.Models.Account;
using ManagementApi.Models.Commander;
using ManagementApi.Models.Common;
using ManagementApi.Models.Corp;
using ManagementApi.Models.Manage.ProjectGroup;
using ManagementApi.Models.Manage.ProjectGroupMember;
using ManagementApi.Models.Person;
using ManagementApi.Models.Project;
using ManagementApi.Models.SysAttachment;
using ManagementApi.Models.System.Dept;
using ManagementApi.Models.Template;
using ManagementApi.Mvc;
using ManagementApi.Mvc.ApplicationContexts;
using ManagementApi.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Modules.Base;
using Modules.CheckIn;
using Modules.CheckIn.Entitys;
using Modules.Commander;
using Modules.Constructor;
using Modules.Corp;
using Modules.Device;
using Modules.FaceScan;
using Modules.FaceScan.Entitys;
using Modules.Person;
using Modules.Project;
using Modules.Project.Entitys;
using Modules.System.Area;
using Modules.System.Attachment;
using Modules.System.Dept;
using Modules.Template;
using Org.BouncyCastle.Utilities.Encoders;
using PmSoft;
using PmSoft.Caching.Redis;
using PmSoft.Entity;
using PmSoft.Exceptions;
using PmSoft.FileStorage;
using PmSoft.Utilities;
using System.ComponentModel.DataAnnotations;
using static Modules.Person.PersonConstants;

namespace ManagementApi.Controllers
{
    /// <summary>
    /// 无鉴权常用业务接口
    /// </summary>
    [ApiController]
    [Route("/api/v1/common")]
    public class CommonController : ControllerBase
    {
        private readonly CorpService corpService;
        private readonly ProjectService projectService;
        private readonly PersonService personService;
        private readonly ConstructorService constructorService;
        private readonly ManagementApplicationContext applicationContext;
        private readonly AreaService areaService;
        private readonly IConfiguration configuration;
        private readonly IMapper mapper;
        private readonly CardReaderService cardReaderService;
        private readonly IFileStorage fileStorage;
        private readonly FacePhotoService personFaceService;
        private readonly CheckInDetailService checkInDetailService;
        private readonly AttachmentService attachmentService;
        private readonly SerialNumberService serialNumberService;
        private readonly DeptService deptService;
        private readonly CommonService commonService;
        private readonly CommanderService commanderService;
        private readonly ProjectGroupMemberService projectGroupMemberService;
        private readonly TemplateService templateService;
        private readonly PersonCertificateDistService personCertificateDistService;
        private readonly CardReaderDeviceService cardReaderDeviceService;
        private readonly ProjectGroupService projectGroupService;
        private readonly PmSoftRedisCache redisCache;
        private readonly IMemoryCache memoryCache;
        private readonly ILogger logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        public CommonController(
            CorpService corpService,
            ProjectService projectService,
            PersonService personService,
             ConstructorService constructorService,
            ManagementApplicationContext applicationContext,
            CardReaderService cardReaderService,
            AreaService areaService,
            IConfiguration configuration,
            IMapper mapper,
            IFileStorage fileStorage,
             FacePhotoService personFaceService,
             CheckInDetailService checkInDetailService,
            AttachmentService attachmentService,
            SerialNumberService serialNumberService,
            DeptService deptService,
            CommonService commonService,
            CommanderService commanderService,
            ProjectGroupMemberService projectGroupMemberService,
            TemplateService templateService,
            PersonCertificateDistService personCertificateDistService,
            CardReaderDeviceService cardReaderDeviceService,
            ProjectGroupService projectGroupService,
            PmSoftRedisCache redisCache,
            IMemoryCache memoryCache,
            ILogger<CommonController> logger
            )
        {
            this.corpService = corpService;
            this.projectService = projectService;
            this.applicationContext = applicationContext;
            this.areaService = areaService;
            this.configuration = configuration;
            this.personService = personService;
            this.constructorService = constructorService;
            this.mapper = mapper;
            this.cardReaderService = cardReaderService;
            this.fileStorage = fileStorage;
            this.personFaceService = personFaceService;
            this.checkInDetailService = checkInDetailService;
            this.attachmentService = attachmentService;
            this.serialNumberService = serialNumberService;
            this.deptService = deptService;
            this.commonService = commonService;
            this.commanderService = commanderService;
            this.projectGroupMemberService = projectGroupMemberService;
            this.templateService = templateService;
            this.personCertificateDistService = personCertificateDistService;
            this.cardReaderDeviceService = cardReaderDeviceService;
            this.projectGroupService = projectGroupService;
            this.redisCache = redisCache;
            this.memoryCache = memoryCache;
            this.logger = logger;
        }

        /// <summary>
        /// 证书类别导入
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="parentId">大类父级id</param>
        [HttpGet("dictImport")]
        public ApiResult<object> dictImport(string value, string parentId)
        {
            string 岗位证书专业 = "普工、初级工、中级工、高级工、技师、高级技师";

            string strSql = "";
            string typeName = "";
            string chr = "";
            string[] 小类;
            string id = "";

            #region 岗位证书专业

            //父级id
            id = "1";
            小类 = 岗位证书专业.Split('、');
            foreach (var item in 小类)
            {
                strSql += $"insert into person_certificate_dist(id,parent_id,level,type,name) values('{Guid.NewGuid().ToString().Replace("-", "")}','{id}',{2},{4},'{item}'); ";
            }

            #endregion 岗位证书专业

            return ApiResult<object>.Success(strSql);
        }

        /// <summary>
        /// 获取全局字典
        /// </summary>
        /// <returns></returns>
        [HttpGet("dict")]
        public ApiResult<DictResultDto> GetGlobalDict()
        {
            DictResultDto resultDto = new();
            string cacheKey = "GlobalDict";

            DictDto? dict = null;
            if (!memoryCache.TryGetValue<DictDto>(cacheKey, out dict))
            {
                dict = DictDto.Instance;
                dict.AreaTrees = areaService.GetAllAreas().AsTrees();
                dict.BankTypeTypes = dict.LoadBankTypeDIC();
                dict.BankSubbranchs = dict.LoadBankSubbranchDIC();
                dict.IndustryTypes = commonService.GetIndustryTypesTree();
                //新的字典在这里继续加
            }

            if (dict == null)
                throw new ArgumentNullException(nameof(dict));

            memoryCache.Set(cacheKey, dict);

            resultDto.Dict = dict;
            var hashCode = dict.GetHashCode();
            resultDto.Version = EncryptionUtility.MD5_16(hashCode.ToString());

            return ApiResult<DictResultDto>.Success(resultDto);
        }

        /// <summary>
        /// 获取全局字典版本
        /// </summary>
        /// <returns></returns>
        [HttpGet("dict_version")]
        public ApiResult<string> GetGlobalDictVersion()
        {
            var hashCode = DictDto.Instance.GetHashCode();
            var version = EncryptionUtility.MD5_16(hashCode.ToString());
            return ApiResult<string>.Success(version);
        }

        /// <summary>
        /// 人员查询/根据项目id
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("persons")]
        public ApiResult<PageDto<PersonInfoDto>> GetPersons([FromQuery] PersonQuery query, int pageIndex = 1, int pageSize = 20)
        {
            var pageDto = personService.GetPersons(query, pageIndex, pageSize).AsPageDto(m => m.AsDto());
            return ApiResult<PageDto<PersonInfoDto>>.Success(pageDto);
        }

        /// <summary>
        /// 获取现场管理人员
        /// </summary>
        /// <returns></returns>
        [HttpGet("worksite_manager/{projectId}")]
        public ApiResult<List<ProjectGroupMemberDto>> GetWorksiteManager(int projectId)
        {
            var list = projectGroupMemberService.GetProjectGroupMembersByProjectId(projectId).Where(i => i.PostCategory == 管理岗位类型.劳资管理员);
            return ApiResult<List<ProjectGroupMemberDto>>.Success(list.AsProjectGroupMemberDtos().ToList());
        }

        /// <summary>
        /// 根据id查询人员详情
        /// </summary>
        /// <param name="personId"></param>
        /// <returns></returns>
        [HttpGet("person/{personId}")]
        public ApiResult<PersonInfoDto> GetPerson(int? personId)
        {
            var data = personService.GetPerson(personId == null ? 0 : (int)personId);
            if (data == null) return ApiResult<PersonInfoDto>.Failure("人员信息不存在");
            return ApiResult<PersonInfoDto>.Success(data.AsDto());
        }

        /// <summary>
        /// 项目查询（所有未登记项目）
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("noRegisterProjects")]
        public ApiResult<PageDto<ProjectRegisterForm>> GetNoRegisterProjects([FromQuery] ProjectInfoQuery query, int pageIndex = 1, int pageSize = 20)
        {
            query.IsRegister = false;
            var pageDto = projectService.GetProjectInfos(query, pageIndex, pageSize).AsPageDto(m => m.AsForm(applicationContext));
            return ApiResult<PageDto<ProjectRegisterForm>>.Success(pageDto);
        }

        /// <summary>
        /// 项目查询(所有项目)
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("projects")]
        public ApiResult<PageDto<ProjectInfoDto>> GetProjects([FromQuery] ProjectInfoQuery query, int pageIndex = 1, int pageSize = 20)
        {
            var pageDto = projectService.GetProjectInfos(query, pageIndex, pageSize).AsPageDto(m => m.AsDto(applicationContext));
            return ApiResult<PageDto<ProjectInfoDto>>.Success(pageDto);
        }

        /// <summary>
        /// 企业查询()
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("corps_pulldown")]
        public ApiResult<IEnumerable<CorpInfo>> GetCorpsPulldown([FromQuery] CorpInfoQuery query, int pageIndex = 1, int pageSize = 9999)
        {
            query.CheckStatus = 审核状态.审核通过;
            var pageDto = corpService.GetCorpInfos(query, pageIndex, pageSize).ToArray();
            return ApiResult<IEnumerable<CorpInfo>>.Success(pageDto);
        }

        /// <summary>
        /// 班组下拉
        /// </summary>
        /// <returns></returns>
        [HttpGet("group_pulldown")]
        public ApiResult<IEnumerable<ProjectGroup>> GetGroupPullDown(int projectId)
        {
            IEnumerable<ProjectGroup> projectGroups = projectGroupService.GetProjectGroupsByProjectId(projectId);
            return ApiResult<IEnumerable<ProjectGroup>>.Success(projectGroups);
        }

        /// <summary>
        /// 企业查询(分页)
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("corps")]
        public ApiResult<PageDto<CorpBaseInfoDto>> GetCorps([FromQuery] CorpInfoQuery query, int pageIndex = 1, int pageSize = 20)
        {
            query.CheckStatus = 审核状态.审核通过;
            var pageDto = corpService.GetCorpInfos(query, pageIndex, pageSize).AsPageDto(m => m.AsBaseInfoDto(applicationContext));
            return ApiResult<PageDto<CorpBaseInfoDto>>.Success(pageDto);
        }

        /// <summary>
        /// 总包+分包企业查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("corps_manager")]
        public ApiResult<IEnumerable<CorpInfoDto>> GetManagerCorps([Required] int projectId)
        {
            var data = corpService.GetCorpsByProjectId(projectId);
            var dtos = data.Select(m => m.AsDto(applicationContext));
            return ApiResult<IEnumerable<CorpInfoDto>>.Success(dtos);
        }

        /// <summary>
        /// 搜索企业
        /// </summary>
        /// <param name="keywords"></param>
        /// <returns></returns>
        [HttpGet("search_corps")]
        public ApiResult<IEnumerable<CorpBaseInfoDto>> SearchCorps([Required][MinLength(2)] string keywords)
        {
            var corps = corpService.SearchCorps(keywords, 10);
            var dtos = corps.Select(m => m.AsBaseInfoDto(applicationContext));
            return ApiResult<IEnumerable<CorpBaseInfoDto>>.Success(dtos);
        }

        /// <summary>
        /// 建设单位下拉
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("constructor_pulldown")]
        public ApiResult<PageDto<LabelValue<int>>> ConstructorPulldown([FromQuery] ConstructorQuery query, int pageIndex = 1, int pageSize = 9999)
        {
            var data = constructorService.GetConstructors(query, pageIndex, pageSize);
            var dtos = data.AsPageDto(source => { return source.AsPullDownDto(); });
            return ApiResult<PageDto<LabelValue<int>>>.Success(dtos);
        }

        /// <summary>
        /// 根据建设单位获取指挥部分页
        /// </summary>
        /// <param name="query"></param>
        /// <param name="constructorId"></param>
        /// <param name="pageNum"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("page_commanders/{constructorId}")]
        public ApiResult<PageDto<CommanderDto>> GetCommander([FromQuery] CommanderQuery query, [Required(ErrorMessage = "建设单位不能为空")] int constructorId, int pageNum = 1, int pageSize = 20)
        {
            query.ConstructorId = constructorId;
            var data = commanderService.GetCommanders(query, pageNum, pageSize);
            var dtos = data.AsPageDto(source => { return source.AsDto(applicationContext); });
            return ApiResult<PageDto<CommanderDto>>.Success(dtos);
        }

        /// <summary>
        /// 根据建设单位获取指挥部下拉
        /// </summary>
        /// <param name="query"></param>
        /// <param name="constructorId"></param>
        /// <param name="pageNum"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("commanders_pulldown/{constructorId}")]
        public ApiResult<PageDto<LabelValue<int>>> GetCommanderPullDown([FromQuery] CommanderQuery query, [Required(ErrorMessage = "建设单位不能为空")] int constructorId, int pageNum = 1, int pageSize = 20)
        {
            query.ConstructorId = constructorId;
            var data = commanderService.GetCommanders(query, pageNum, pageSize);
            var dtos = data.AsPageDto(source => { return source.AsPullDownDto(); });
            return ApiResult<PageDto<LabelValue<int>>>.Success(dtos);
        }

        /// <summary>
        /// 根据id查询企业详情
        /// </summary>
        /// <param name="corpId"></param>
        /// <returns></returns>
        [HttpGet("corp/{corpId}")]
        public ApiResult<CorpInfoDto> GetCorp(int corpId)
        {
            var data = corpService.GetCorpInfo(corpId);
            if (data == null) return ApiResult<CorpInfoDto>.Failure("企业信息不存在");
            return ApiResult<CorpInfoDto>.Success(data.AsDto(applicationContext));
        }

        /// <summary>
        /// 根据行业分类及区域代码获取监管单位
        /// </summary>
        /// <param name="industryType"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        [HttpGet("getDeptPullDown")]
        public ApiResult<IEnumerable<LabelValue<int>>> GetDeptPullDown([Required(ErrorMessage = "行业分类不能为空")] 行业主管部门 industryType, [Required(ErrorMessage = "区域编码不能为空")] int areaCode)
        {
            var data = deptService.GetDeptsByIndustryTypeAndAreaCode(industryType, areaCode).AsPullDownDto();
            return ApiResult<IEnumerable<LabelValue<int>>>.Success(data);
        }

        #region 模板

        /// <summary>
        /// 获取模板
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpGet("getTemplates/{type}")]
        public ApiResult<IEnumerable<SysTemplateDto>> GetTemplates(模板类型 type)
        {
            return ApiResult<IEnumerable<SysTemplateDto>>.Success(templateService.GetTemplates(type).AsDtos());
        }

        /// <summary>
        /// 下载模板
        /// </summary>
        /// <param name="attachmentId"></param>
        /// <returns></returns>
        [HttpGet("downloadTemplate/{attachmentId}")]
        public IActionResult DownloadTemplates(string attachmentId)
        {
            var attachment = templateService.GetTemplate(attachmentId) ?? throw new BusinessException("附件不存在"); ;
            byte[] objectData = fileStorage.GetFileAsync(attachment.BucketName, attachment.ObjectFilePath).GetAwaiter().GetResult();
            return File(objectData, attachment.ContentType, attachment.FriendlyName);
        }

        //public ApiResult<IEnumerable<SysAttachmentDto>> GetAttachments() {
        //}

        /// <summary>
        /// 下载附件
        /// </summary>
        /// <param name="attachmentId"></param>
        /// <returns></returns>
        [HttpGet("download/{attachmentId}")]
        public IActionResult DownloadTemplate(string attachmentId)
        {
            var attachment = attachmentService.GetAttachmentInfo(attachmentId) ?? throw new BusinessException("附件不存在");
            byte[] objectData = fileStorage.GetFileAsync(attachment.BucketName, attachment.ObjectFilePath).GetAwaiter().GetResult();
            return File(objectData, attachment.ContentType, attachment.FriendlyName);
        }

        #endregion 模板

        #region 身份证读卡器相关

        /// <summary>
        /// 获取读卡器签名
        /// </summary>
        /// <returns></returns>
        [HttpGet("getReadCardToken")]
        public ApiResult<string> GetReadCardToken(string? corpCode)
        {
            #region 尝试通过当前项目获取总包企业信用代码

            if (string.IsNullOrEmpty(corpCode) && applicationContext.CurrentUser is IProjectUser projectUser && projectUser.ProjectId.HasValue)
            {
                var projectInfo = applicationContext.GetService<ProjectService>().GetProjectInfo(projectUser.ProjectId.Value);
                if (projectInfo != null)
                {
                    var corpInfo = corpService.GetCorpInfo(projectInfo.LumpContractorCorpId);
                    if (corpInfo != null)
                        corpCode = corpInfo.Code;
                }
            }

            #endregion 尝试通过当前项目获取总包企业信用代码

            string readId = Guid.NewGuid().ToString();
            string token = ReaderEncrypt.AESEncrypt($"{readId},{corpCode}", isHex: true);
            return ApiResult<string>.Success(token);
        }

        /// <summary>
        /// 身份证阅读器上报
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        /// <exception cref="BusinessException"></exception>
        [HttpPost("reportReadCard")]
        public ApiResult<string> ReportReadCard([FromForm] CardReadReq req)
        {
            logger.LogInformation($"接收身份证阅读器传过来的参数:{req}");
            cardReaderService.CheckReadAsync(req.Data);
            return ApiResult<string>.Success("上报成功");
        }

        /// <summary>
        /// 同意接入读卡器
        /// </summary>
        /// <returns></returns>
        [HttpPut("confirmCardReader")]
        public ApiResult ConfirmCardReader([Required(ErrorMessage = "施工总包信用代码不能为空")] string corpCode)
        {
            var cardReaders = cardReaderDeviceService.GetCardReaderDeviceByCorpCode(corpCode);
            //筛选非待审核的读卡器，大于0则不允许自动审核
            if (cardReaders.Count() > 1 && cardReaders.Any(m => m.Status != 设备审核状态.待审核))
                return ApiResult.Failure("企业已接入了至少一个读卡器，接入多个需要联系管理员登记读卡器信息,联系电话：13398001090");

            //获取企业最新创建的一个待审核读卡器
            var cardReader = cardReaders.OrderByDescending(m => m.CreateTime).FirstOrDefault(m => m.Status == 设备审核状态.待审核);
            if (cardReader == null)
                return ApiResult.Failure("未获取到当前企业待登记读卡器信息");
            cardReader.Status = 设备审核状态.已审核;
            cardReader.AuditTime = DateTime.Now;
            cardReader.Description = "企业首个身份证读卡器自动登记";
            cardReaderDeviceService.UpdateSysDevice(cardReader);
            return ApiResult.Success("读卡器接入成功");
        }

        /// <summary>
        /// 根据签名获取读卡结果
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet(nameof(GetCardInfo))]
        public ApiResult<CardInfo> GetCardInfo([Required] string token)
        {
            var cardInfo = cardReaderService.GetCardInfo(token);
            return ApiResult<CardInfo>.Success(cardInfo);
        }

        #endregion 身份证读卡器相关

        #region 人脸图片预览

        /// <summary>
        /// 人脸认证图片预览
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet("OpenImage/{code}")]
        public async Task<IActionResult> OpenImage(string code)
        {
            FacePhoto? personFace = personFaceService.GetPersonFace(code);
            if (personFace == null) return NotFound();

            string photoPath = string.IsNullOrEmpty(personFace.VerifyPhoto) ? personFace.IdCardPhoto : personFace.VerifyPhoto;
            byte[] objectData = await fileStorage.GetFileAsync(FileBuckets.Person, photoPath);

            var result = File(objectData, "image/jpeg", false);
            return result;
        }

        /// <summary>
        /// 考勤图片预览
        /// </summary>
        /// <param name="id"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        [HttpGet("getImage/{id}/{month}")]
        public ApiResult<string> getImage(string id, int month)
        {
            CheckInDetail? entity = checkInDetailService.GetCheckInDetail(id, month);
            if (entity == null) return ApiResult<string>.Failure("考勤记录不存在");
            byte[] objectData = fileStorage.GetFileAsync(FileBuckets.Checkin, entity.FacePath).GetAwaiter().GetResult();
            var imgBase64 = "data:image/png;base64," + Base64.ToBase64String(objectData);
            return ApiResult<string>.Success(imgBase64);
        }

        #endregion 人脸图片预览

        #region 上传文件相关

        /// <summary>
        /// /上传文件
        /// </summary>
        /// <returns></returns>
        [HttpPost("upload")]
        public ApiResult<string> FileUpload([FromForm] IFormCollection formData)
        {
            if (formData.Files.Count > 0)
            {
                return ApiResult<string>.Success(attachmentService.CreateTemporaryAsync(formData.Files[0]).GetAwaiter().GetResult());
            }
            return ApiResult<string>.Failure("请上传文件");
        }

        /// <summary>
        /// /上传图片
        /// </summary>
        /// <returns></returns>
        [HttpPost("upload-img")]
        public ApiResult UploadImage(string guid, [FromForm] IFormCollection formData)
        {
            if (string.IsNullOrEmpty(guid)) return ApiResult.Failure("guid不能为空");
            if (formData.Files.Count == 0) return ApiResult.Failure("请上传文件");
            IFormFile formFile = formData.Files[0];
            string orgFileName = Path.GetFileName(formFile.FileName);
            string extension = Path.GetExtension(orgFileName).ToLower();
            string tempId = Guid.NewGuid().ToString().Replace("-", "");
            extension = (extension.StartsWith(".") ? extension : "." + extension);
            if (!new List<string> { ".jpg", ".png" }.Exists(i => i == extension))
            {
                throw new BusinessException("不支持的上传文件类型");
            }
            if (formFile.Length > 5242880)
            {
                throw new BusinessException("文件大小不能超过5M");
            }
            string fileName = tempId + extension;
            string saveFileName = guid + "/" + fileName;
            fileStorage.PutFileAsync(FileBuckets.Editor, saveFileName, formFile.OpenReadStream()).GetAwaiter().GetResult();
            var obj = new
            {
                url = "/api/v1/common/editor_img?guid=" + guid + "&name=" + fileName,
                alt = formFile.FileName,
                href = "",
            };
            return ApiResult.Success("上传成功", obj);
        }

        /// <summary>
        /// 富文本显示图片
        /// </summary>
        /// <param name="guid">图片关联主键</param>
        /// <param name="name">文件名</param>
        /// <returns></returns>
        [HttpGet("editor_img")]
        public IActionResult EditImage(string guid, string name)
        {
            if (string.IsNullOrEmpty(guid)) throw new BusinessException("guid不能为空");
            if (string.IsNullOrEmpty(name)) throw new BusinessException("文件名不能为空");
            string saveFileName = guid + "/" + name;
            byte[] objectData = fileStorage.GetFileAsync(FileBuckets.Editor, saveFileName).GetAwaiter().GetResult();
            var result = File(objectData, "image/jpeg", false);
            return result;
        }

        #endregion 上传文件相关

        #region 密码强度检测

        /// <summary>
        /// 密码强度检测
        /// </summary>
        /// <param name="passWord"></param>
        /// <returns></returns>
        [HttpGet("getPasswordStrength")]
        public ApiResult<PasswordStrength> GetPasswordStrength([Required(ErrorMessage = "密码不能为空")] string passWord)
        {
            PasswordStrength passwordStrength = PasswordChecker.CheckPasswordStrength(passWord);
            return ApiResult<PasswordStrength>.Success(passwordStrength);
        }

        #endregion 密码强度检测
    }
}